package dao;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Random;

import domain.Question;
import util.MySpring;
import util.QuestionFileReader;

public class QuestionDao {
	//负责读取文件 
	//随机生成一套试卷  
	private QuestionFileReader reader = MySpring.getBean("util.QuestionFileReader");
	//将缓存中的集合临时改为List集合  随机找寻元素的时候存在位置
	private ArrayList<Question> questionBank = new ArrayList(reader.getQuestionBox());
	
	public ArrayList<Question> getPaper(int count){//指定题数
		HashSet<Question> paper = new HashSet<>();
		while(paper.size()!=count) {
			Random r = new Random();
			int index = r.nextInt(this.questionBank.size());//[0,size)
			paper.add(this.questionBank.get(index));
		}
		return new ArrayList<Question>(paper);	
	}
	
}
